from dronekit import connect, VehicleMode
from time import sleep

import config

class action:
# Basic control
    def pwm_change(ch_name, flag):
        if flag == True:
            config.pwm_value[ch_name] += config.pwm_step[ch_name]
        else:
            config.pwm_value[ch_name] -= config.pwm_step[ch_name]
        
        config.vehicle.channels.overrides[str(ch_name)] = config.pwm_value[ch_name]
        print("Ch ", str(ch_name), ": ",  config.pwm_value[ch_name])

# Flight modes
    def stabilize():
        config.vehicle.mode = VehicleMode("STABILIZE")
    def alt_hold():
        config.vehicle.mode = VehicleMode("ALT_HOLD")

# Arming 
    def arm():
        while not config.vehicle.armed:
            config.vehicle.armed = True
            sleep(2)
    def disarm():
        config.vehicle.armed = False

    def reset():
        vehicle.channels.overrides[config.rcmap.throttle.value] = config.pwm_value[config.rcmap.throttle.value]
        config.vehicle.armed = False
        for i in range(1, 5):
            vehicle.channels.overrides[str(i)] = config.pwm_value[i]
        config.vehicle.armed = False



    
